package commons.base.db;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class DbExample {

	public static void main(String[] args) throws SQLException {
//		t2();
		System.err.println(String.class.cast(null));
	}
	
	public static void t1()throws SQLException{
		String sql = "select * from user limit 3";
		
		List<Map<String, Object>> results = Databases.getDatabase("local").queryMultiColumn(sql);

		for(Map<String, Object> row : results){
			System.err.println(row.get("id") + ", " + row.get("username"));
		}
		
		Databases.shutdown();
	}
	
	public static void t2()throws SQLException{
		TransactionOp op = null;
		try {
			op = Databases.getDatabase("local").beginTransaction();
			op.update("update user set isBlock=1 where id=1595");
			
			int i = 10/0;
			System.out.println(i);
			
			op.update("update user set isBlock=1 where id=1596");
			
			op.commit();
		} catch (Exception e) {
			e.printStackTrace();
			op.rollback();
		}finally{
			if(op != null) op.endTransaction();
			
			Databases.shutdown();
		}
	}
	
}
